<?php

namespace App\Models;


class Forwarder extends BaseModel
{
    protected $table = 'forwarders';

    protected $fillable = [
        'user_id',
        'name',
        'subject_id',
        'img',
        'intro',
        'deduction',
        'city',
        'status',
        'qrcode',
        'forbid_at',
    ];

    protected $appends = ['status_att', 'is_forbid'];

    public static $EnumMonthly = [
        0 => '否', 1 => '是'
    ];
    public static $EnumStatus = [
        0 => '审核中', 1 => '正常', 2 => '停止接单', 3 => "取消申请"
    ];

    public function getStatusAttAttribute()
    {
        return self::$EnumStatus[$this->status] ?? $this->status;
    }

    public function getIsForbidAttribute()
    {
        return ($this->forbid_at && strtotime($this->forbid_at) > time()) ? 1 : 0;
    }
    public function user()
    {
        return $this->hasOne('App\Models\User', 'id', 'user_id');
    }

    public function subject()
    {
        return $this->hasOne('App\Models\Subject', 'id', 'subject_id');
    }

    public function forwarderStat()
    {
        return $this->hasOne('App\Models\ForwarderStat', 'forwarder_id', 'id');
    }
}
